package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Complaint;
import com.ruoyi.system.mapper.ComplaintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ComplainttypeMapper;
import com.ruoyi.system.domain.Complainttype;
import com.ruoyi.system.service.IComplainttypeService;
import com.ruoyi.common.support.Convert;

/**
 * 投诉类型 服务层实现
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Service
public class ComplainttypeServiceImpl implements IComplainttypeService 
{
	@Autowired
	private ComplainttypeMapper complainttypeMapper;
	@Autowired
	private ComplaintMapper complaintMapper;

	/**
     * 查询投诉类型信息
     * 
     * @param complainttypeId 投诉类型ID
     * @return 投诉类型信息
     */
    @Override
	public Complainttype selectComplainttypeById(Integer complainttypeId)
	{
	    return complainttypeMapper.selectComplainttypeById(complainttypeId);
	}
	
	/**
     * 查询投诉类型列表
     * 
     * @param complainttype 投诉类型信息
     * @return 投诉类型集合
     */
	@Override
	public List<Complainttype> selectComplainttypeList(Complainttype complainttype)
	{
	    return complainttypeMapper.selectComplainttypeList(complainttype);
	}
	
    /**
     * 新增投诉类型
     * 
     * @param complainttype 投诉类型信息
     * @return 结果
     */
	@Override
	public int insertComplainttype(Complainttype complainttype)
	{
	    return complainttypeMapper.insertComplainttype(complainttype);
	}
	
	/**
     * 修改投诉类型
     * 
     * @param complainttype 投诉类型信息
     * @return 结果
     */
	@Override
	public int updateComplainttype(Complainttype complainttype)
	{
	    return complainttypeMapper.updateComplainttype(complainttype);
	}

	/**
     * 删除投诉类型对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteComplainttypeByIds(String ids)
	{
		return complainttypeMapper.deleteComplainttypeByIds(Convert.toStrArray(ids));
	}

	/**
	 * 根据客户投诉ID查询所有投诉类型
	 * @param complaintId 要查询的投诉ID
	 * @return 投诉类型结果
	 */
	@Override
	public List<Complainttype> selectComplaintIdList(Integer complaintId) {
		Complaint complaint = complaintMapper.selectComplaintById(complaintId);
		List<Complainttype> complainttypes = complainttypeMapper.selectComplainttypeList(null);
		for (Complainttype complainttype:complainttypes){
			if(complainttype.getComplainttypeId()==complaint.getComplaintTypeId()){
				complainttype.setFlag(true);
			}
		}
		return complainttypes;
	}

}
